 <?php
class SpecialAction extends BaseAction{	
	// 显示专题
    public function show(){
		//获取地址栏参数
		$admin['cid']= $_REQUEST['cid'];
		$admin['continu'] = $_REQUEST['continu'];
		$admin['status'] = intval($_REQUEST['status']);
		$admin['player'] = trim($_REQUEST['player']);
		$admin['stars'] = intval($_REQUEST['stars']);
		$admin['type'] = !empty($_GET['type'])?$_GET['type']:C('admin_order_type');
		$admin['order'] = !empty($_GET['order'])?$_GET['order']:'desc';
		$admin['orders'] = 'vod_'.$admin["type"].' '.$admin['order'];
		$admin['wd'] = urldecode(trim($_REQUEST['wd']));
		$admin['p'] = '';
	    $rs = D("Special");
		$list = $rs->where($where)->order('special_id desc')->select();
		foreach($list as $key=>$val){
			$list[$key]['slide_pic'] = ff_img_url($list[$key]['slide_pic']);	
		}		
		$this->assign('list',$list);
		$this->display('./Public/system/special_show.html');
    }
	// 添加与编辑专题
    public function add(){
		$where['special_id'] = intval($_GET['id']);
		if ($where['special_id']) {
			$rs = D("Special");
			$array = $rs->where($where)->find();
			if (C('admin_time_edit')){
				$array['checktime'] = 'checked';
			}	
			$array['tpltitle'] = '编辑';
			$array['countvod'] = count(explode(',',$array['special_vids']));
			$array['countnews'] = count(explode(',',$array['special_nids']));
		}else{
			$array['special_addtime'] = time();
			$array['checktime'] = 'checked';
			$array['tpltitle'] = '添加';
			$array['countvod'] = 0;
			$array['countnews'] = 0;		
		}
		$this->assign($array);
		$this->display('./Public/system/special_add.html');
    }
	// 添加幻灯片并写入数据库
	public function insert(){
		$rs = D("Special");
		if ($rs->create()) {
			if ( false !== $rs->add() ) {
				redirect('index.php?s=Admin-Special-Show');
			}else{
				$this->error('添加专题失败');
			}
		}else{
		    $this->error($rs->getError());
		}		
	}	
	// 更新专题
	public function update(){
		$rs = D("Special");
		if ($rs->create()) {
			$list = $rs->save();
			if ($list !== false) {
			    redirect('index.php?s=Admin-Special-Show');
			}else{
				$this->error("更新专题失败!");
			}
		}else{
			$this->error($rs->getError());
		}
	}
	// 隐藏与显示专题
    public function status(){
		$where['special_id'] = intval($_GET['id']);
		$rs = D("Special");
		if(intval($_GET['sid'])){
			$rs->where($where)->setField('special_status',1);
		}else{
			$rs->where($where)->setField('special_status',0);
		}
		redirect($_SERVER['HTTP_REFERER']);
    }
	// 删除专题
    public function del(){
		$this->delfile(intval($_GET['id']));
		$this->redirect('index.php?s=Admin-Special-Show');
    }
	// 删除专题all
    public function delall(){
		if(empty($_POST['ids'])){
			$this->error('请选择需要删除的专题!');
		}	
		$array = $_POST['ids'];
		foreach($array as $val){
			$this->delfile($val);
		}
		redirect($_SERVER['HTTP_REFERER']);
    }
	// 删除静态文件与图片
    public function delfile($id){
		$where['special_id'] = $id;
		$rs = D("Special");
		$rs->where($where)->delete();
    }
	// 展示影视列表
    public function ajaxvod(){
		$rs = D("Vod");
		$count = $rs->count('vod_id');
		$totalpages = ceil($count/C('url_num_admin'));
		$currentpage = !empty($_GET['p'])?intval($_GET['p']):1;
		$currentpage = get_maxpage($currentpage,$totalpages);
	    $list = $rs->field('vod_id,vod_cid,vod_name')->order('vod_addtime desc,vod_id desc')->limit(15)->page($currentpage)->select();
		$this->assign('list_vod',$list);
		$this->display('./Public/system/special_vids.html');
    }											
}
?>